package org.example.utils;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class TextUtils {

    public String processTextFile(String filePath) {
        StringBuilder result = new StringBuilder();

        try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
            String line;
            while ((line = br.readLine()) != null) {
                // 将非字母字符替换为空格，并转换为小写
                line = line.replaceAll("[^a-zA-Z]+", " ").toLowerCase().trim();
                result.append(line).append(" "); // 将每行结果添加到总结果，并添加空格分隔
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        return result.toString().trim(); // 返回结果并去除末尾可能的空格
    }


}
